//
//  PreviewViewController.m
//  Contractor
//
//  Created by 金鑫 on 16/6/2.
//  Copyright © 2016年 star j. All rights reserved.
//

#import "PreviewViewController.h"
#import "IanScrollView.h"
#import "CONST.h"

@interface PreviewViewController ()

@end

@implementation PreviewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createScrollView] ;
}

- (void)viewWillAppear:(BOOL)animated
{
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;
    self.view.backgroundColor = [UIColor blackColor] ;
    self.navigationItem.title = @"图片预览" ;
    UILabel *label = [[UILabel alloc] init] ;
    label.font = [UIFont fontWithName:@"AvenirLTStd-Light" size:16.0f] ;
    label.backgroundColor = [UIColor clearColor] ;
    label.text = [NSString stringWithFormat:@"%ld/%lu",_index+1,(unsigned long)_array.count];
    label.textAlignment = NSTextAlignmentCenter ;
    label.textColor = [UIColor whiteColor] ;
    label.frame = CGRectMake(0, 0, 50, 18.0f) ;
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:label] ;
    
    self.navigationItem.rightBarButtonItem = rightItem ;
}

-(void)createScrollView
{
    IanScrollView *scrollView = [[IanScrollView alloc] initWithFrame:CGRectMake(0, 20, __kScreenWidth, self.view.frame.size.height-100)];
    
    scrollView.backgroundColor = [UIColor blackColor] ;
    NSMutableArray *array = [NSMutableArray arrayWithArray:_array];
    scrollView.slideImagesArray = array;
    [scrollView startLoadingByIndex:_index] ;
    [self.view addSubview:scrollView] ;
    scrollView.ianCurrentIndex = ^(NSInteger index){
        UILabel *label = [[UILabel alloc] init] ;
        label.font = [UIFont fontWithName:@"AvenirLTStd-Light" size:16.0f] ;
        label.backgroundColor = [UIColor clearColor] ;
        label.text = [NSString stringWithFormat:@"%ld/%lu",index+1,(unsigned long)_array.count];
        label.textAlignment = NSTextAlignmentCenter ;
        label.textColor = [UIColor whiteColor] ;
        label.frame = CGRectMake(0, 0, 50, 18.0f) ;
        
        UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:label] ;
        
        self.navigationItem.rightBarButtonItem = rightItem ;
    } ;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
